package com.zn.log
{
    import com.zn.utils.DateFormatter;

    import flash.utils.getQualifiedClassName;

    import mx.utils.ObjectUtil;

    /**
     *日志
     * @author zn
     *
     */
    public class Log
    {
        public static var loginTargetList:Vector.<ILoggingTarget> = new Vector.<ILoggingTarget>();

		public static var dataList:Array=[];
		
		public static var printInfo:Boolean=true;
		
        public function Log()
        {
        }

        public static function debug(objectClass:Class, methodName:String, value:Object):void
        {
            var str:String = "type:" + getQualifiedClassName(objectClass) + " " +
                "methodName:" + methodName + " " +
                "info:" + ObjectUtil.toString(value);

            send(formatInfo(str, "debug"));
        }

        public static function error(objectClass:Class, methodName:String, value:Object):void
        {
            var str:String = "type:" + getQualifiedClassName(objectClass) + " " +
                "methodName:" + methodName + " " +
                "info:" + ObjectUtil.toString(value);

            send(formatInfo(str, "error"));
        }

        private static function formatInfo(value:String, type:String):String
        {
            var date:String = "";
            var d:Date = new Date();
			
			date=DateFormatter.formatterTimeAll(d.time);

            var category:String = "[" + type + "]" + "  ";

            return date + category + value;
        }

        private static function send(value:String):void
        {
			value+=	"\n----------------------------------------------------------------------------------------------------------------------------------------------------------\n\n";
            print(value);

			dataList.push(value);
			
			if(dataList.length>20)
				dataList.splice(0,10);
			
            var logginTarget:ILoggingTarget;
            for (var i:int = 0; i < loginTargetList.length; i++)
            {
                logginTarget = loginTargetList[i];
                logginTarget.send(value);
            }
        }

        private static function print(value:String):void
        {
			if(printInfo)
            	trace(value);
        }
    }
}
